<template>
	<view>
		<view class="cu-item bg-white margin-lr-sm radius margin-top-sm space-between" :class="[value.myGet?'opacity':'']"
		 v-if="value">
			<view class="w100 padding-sm text-left">
				<view class="text-lg text-black margin-top">{{value.title}}</view>
				<view class="text-gray margin-tb-sm">
					
				</view>
				<view class="text-gray">
					
				</view>
			</view>
			<view class="console-control  padding-sm text-center opacity" :class="'bg-'+theme" v-if="value.use_order_id > 0">
				<view class="text-white">
					<block >
						<text class="text-xxxl ">{{value.money}}</text>
					</block>
					
				</view>
				<view class="text-white text-sm margin-top-xs"></view>
				<view class="text-white" v-if="value.get_type>1">
					转赠
				</view>
				<view class="text-white" v-else>
					订单
				</view>
			</view>
			
			<view class="console-control padding-sm text-center" :class="'bg-'+theme" v-else>
				<!-- <view class="text-white">
					<block >
						<text class="text-xxxl ">{{value.money}}</text>
					</block>
					
				</view> -->
				<view class="text-white text-sm margin-top-xs"></view>
				<view class="cu-btn sm bg-white round  margin-top-sm" >
					<text  @tap="goUseCreate(value)">立即打开</text>
				</view>
				<view class="cu-btn sm bg-white round  margin-top-sm" >
					<text  @tap="goUse(value)">立即转赠</text>
				</view>
				<view class="cu-btn sm bg-white round  margin-top-sm" @tap="goCreate(value)" >立即分享</view>
			</view>
		</view>
		<view class="cu-modal" :class="shareimg==''?'':'show'">
			<view class="cu-dialog show-none" @click="couponhideModal" v-if="shareimg">
				<view class="cu-bar  justify-end">
					<view class="action" bindtap="couponhideModal">
						<text class="cuIcon-close text-red" @click="couponhideModal"></text> 
					</view>
				</view>
				<image v-if="shareimg && shareimg" :src="shareimg" mode="aspectFill" class="gzh_qrcode"></image>
			</view>
		</view>
		<view class="cu-modal" :class="openimg?'show':''">
			<view class="cu-dialog show-none"  v-if="openimg">
				<view class="cu-bar  justify-end">
					<view class="action" bindtap="openModal">
						<text class="cuIcon-close text-red" @click="openModal"></text> 
					</view>
				</view>
				<view>
					<view class="my-data-box">
						<view class="my-data-box-content-inputbox">
							<view class="input-line">		
								<input class="input-mobile" type="number" placeholder="请输入赠送人的电话/uid" v-model="formData.mobile" placeholder-class="my-input-holder"/>
							</view>
						</view>
					</view>
					
					<view class="my-data-box-submitbox" >
						<view class="my-data-box-content-submitbox">
							<button @tap="showConf">确认转赠</button>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		components: {},
		props: {
			value: {
				type: Object,
				default: null
			},
			isGoods: {
				type: Boolean,
				default: false
			}
		},
		filters: {
			mathTruePrice(value, discount) {
				return (parseFloat(value) * parseFloat(discount) / 100).toFixed(2)
			},
		},
		created: function(e) {
			this.now = new Date().getTime() / 1000
		},
		data() {
			return {
				now: 0,
				CLOUDPATH: this.$config.cloudPath,
				theme: this.$config.THEME(),
				loading: false,
				shareimg:'',
				openimg:false,
				coupon_id:0,
				formData:{
					mobile:'',
				},
			}
		},
		methods: {
			showConf(){
				let formData = this.formData
				if (!formData.mobile.trim()) {
					this.$common.showError('请填写手机号码')
					return
				}
				// if (!(/^1(2|3|4|5|6|7|8|9)\d{9}$/.test(formData.mobile))) {
				// 	this.$common.showError('请输入正确的手机号')
				// 	return
				// }
				this.$http
					.post('coupon_confirm_open', {coupon_id: this.coupon_id,mobile:formData.mobile})
					.then((response) => {
						
							if(response.data.code==200){
								this.$common.showSuccess('赠送成功',(r)=>{
									uni.navigateTo({
										url:'/pages/member/index'
									})
								})
							}else{
								this.$common.showError(response.data.message)
							}				
					})
					.catch((response) => {
						this.$common.showError(response.data.message)
					})
			},
			couponhideModal()
			{
				this.shareimg=""
			},
			openModal()
			{
				this.openimg=false
			},
			goUseCreate(value) {
				if (this.$common.loginAuth(true)) {
					uni.showLoading({
						title: '加载中...',
					})
					this.$http
						.post('open_coupon_confirm', {coupon_id: value.id})
						.then((response) => {
								if(response.data.code==200){
									this.$common.showSuccess('打开成功',(r)=>{
										uni.navigateTo({
											url:'/pages/member/index'
										})
									})
								}else{
									this.$common.showError(response.data.message)
								}				
						})
						.catch((response) => {
							this.$common.showError(response.data.message)
						})

				}
			},
			goCreate(value) {
				if (this.$common.loginAuth(true)) {
					uni.showLoading({
						title: '加载中...',
					})
					this.$http.post('get_poster', {
						type: 'coupon',
						id: value.id,
						share_url: "pages/member/coupon_apply",
						member_id: value.member_id,
						member_name: value.title,
						member_head: "",
						member_level: 0,
						reget: true
					}).then((res) => {
						this.shareimg = res.data.data
						console.log(this.shareimg)
						uni.hideLoading();
					})

				}
			},
			goUse(value) {
				this.coupon_id=value.id
				console.log(this.coupon_id)
				this.openimg=true
			}
		},
	}
</script>

<style>
	.console-control {
		min-width: 200rpx;
		border-radius: 18upx 0 0 18upx;
	}

	.text-xxxl {
		font-size: 40rpx;
	}

	.opacity {
		opacity: 0.5;
	}

	.useimg {
		width: 80rpx;
		height: 80rpx;
	}
</style>
